#include <stdio.h>

int main(int argc, char const *argv[])
{
    char star[8], groud[8], *sp, *gp;
    int s = 1, g = 1;
    gets(star);
    gets(groud);
    sp = star;
    while (*sp)
    {
        s *= *sp - 'A' + 1;
        sp++;
    }
    gp = groud; 
    while (*gp)
    {
        g *= *gp - 'A' + 1;
        gp++;
    }
    printf("%s", (s % 47) == (g % 47) ? "GO" : "STAY");
    return 0;
}
